
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';

export default defineConfig({
  plugins: [vue()],
  base: './',
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '@vue/shared': path.resolve(__dirname, 'node_modules/@vue/shared')
    }
  },
  optimizeDeps: {
    include: ['@vue/shared', 'element-plus'],
    esbuildOptions: {
      target: 'es2020'
    }
  },
  build: {
    outDir: 'dist', // 确保输出目录正确
    assetsDir: 'assets', // 静态资源目录
    rollupOptions: {
      output: {
        // 确保静态资源文件名不包含哈希值，便于调试
        assetFileNames: 'assets/[name].[ext]',
        chunkFileNames: 'assets/[name].js',
        entryFileNames: 'assets/[name].js'
      }
    }
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://63cb0723.r38.cpolar.top',
        changeOrigin: true,
        credentials: 'include',
        rewrite: (path) => path.startsWith('/api') ? path.slice(4) : path
      }
    }
  }
});
